package com.xry.service.impl;

import com.xry.annotation.LogMethod;
import com.xry.bean.Buycar;
import com.xry.mapper.BuycarDao;
import com.xry.service.BuycarService;
import com.xry.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BuycarServiceImpl implements BuycarService {
    @Autowired
    BuycarDao buycarDao;
    @Override
    @LogMethod(serviceName = "增加购物车信息")
    public Buycar add(Buycar buycar) {
        //新增数据
        buycarDao.add(buycar);
        //通过主键查询数据库中的数据
        Buycar result = buycarDao.one(buycar.getId());
        return result;
    }

    @Override
    @LogMethod(serviceName = "修改购物车信息")
    public int del(Integer id) {
        return buycarDao.del(id);
    }


    @Override
    @LogMethod(serviceName = "修改购物车信息")
    public Buycar edit(Buycar buycar) {
        buycarDao.edit(buycar);
        Buycar result=buycarDao.one(buycar.getId());
        return result;
    }

    @Override
    public List<Buycar> all(Buycar buycar) {
        return buycarDao.all( buycar);
    }

    @Override
    public Buycar one(Integer id) {
        return buycarDao.one(id);
    }

    @Override
    public void page(Page page, Buycar buycar){
        int count=buycarDao.pageCount(buycar);
        Object data=buycarDao.page(page,buycar);
        page.setCount(count);
        page.setData(data);
    }
}
